package com.genokon.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.genokon.dto.VarComputeDto;
import com.genokon.dto.VarParams;
import com.genokon.dto.VariationDto;
import com.genokon.entry.GeneVariationInfo;
import com.genokon.service.VariationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author by baichaoda
 * @date 2020/11/4 11:14
 */
@RestController()
@RequestMapping("/var")
public class VariationController {
    @Resource
    private VariationService variationService;

    @PostMapping("/add")
    R<Long> addVariation(VariationDto dto){
        R<Long> result;
        try {
            result = R.ok(variationService.addVariation(dto));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }

    @GetMapping("/search")
    R<List<VariationDto>> searchVar(VarParams params){
        R<List<VariationDto>> result;
        return R.ok(variationService.getVariation(params));
    }

    @GetMapping("/get")
    R<VarComputeDto> searchVar(GeneVariationInfo params){
        R<VarComputeDto> result;
        try {
            result = R.ok(variationService.getVariationById(params));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }

    @GetMapping("/rate")
    R<Double> rateVar(GeneVariationInfo params){
        R<Double> result;
        try {
            result = R.ok(variationService.rateVariation(params));
        } catch (Exception e) {
            result = R.failed(e.getMessage());
        }
        return result;
    }

}
